package com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck;

import com.personal.gateway.custom.customException.ConfigurationOptionCheckException;
import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.ConfigurationTypeDouble;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

/**
 * @author BigHead
 * @date 2022/1/11 10:57
 * @description ParameterCheckString
 */
public class ParameterCheckDouble extends AbstractParameterCheck<Double, ConfigurationTypeDouble> {


    @Override
    public Double abstractCheckValue(ConfigurationOption<Double, ConfigurationTypeDouble> configurationOption, String value) {
        if (StringUtils.isNotEmpty(value)) {
            if (!NumberUtils.isParsable(value)) {
                throw new ConfigurationOptionCheckException(value, configurationOption);
            }
            return Double.valueOf(value);
        }
        return null;
    }
}
